(function () {
    'use strict';

    angular.module('app')
        .controller('SysDeptListCtrl', SysDeptListCtrl);

    SysDeptListCtrl.$inject = ['$rootScope', '$scope', '$state','dialogs','SysDeptService'];
    function SysDeptListCtrl($rootScope, $scope,$state,dialogs, sysDeptService) {

		$scope.title = '部门管理';
		$scope.params = {
            pageNum: 1,
            pageSize: 20,
            orderBy: ''
        };

		$scope.search = function () {
			$rootScope.loading = true;
            sysDeptService.list($scope.params)
                .then(function (data) {
					$scope.pageInfo = data;
                })
                .finally(function () {
					$rootScope.loading = false;
                })
            ;
        };

		$scope.search();


        $scope.delete = function (id) {
            dialogs.confirm('确认', '要删除此部门吗？', {
                size: 'md'
            })
                .result.then(function () {
                    sysDeptService.deleteById(id)
                    .then(function () {
                            $state.reload();
                    })
                ;
            });
        };

		$scope.pageChanged = function () {
			$scope.params.pageNum = $scope.pageInfo.pageNum;
				$scope.search();
        };
    }
})();